# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Daniel Sabogal <dsabogalcc@gmail.com>
pkgname=libinput
pkgver=1.21.0
pkgrel=0
pkgdesc="Library for handling input devices"
url="https://www.freedesktop.org/wiki/Software/libinput"
arch="all"
license="MIT"
_depends_tools="python3 py3-libevdev py3-udev py3-yaml"
makedepends="eudev-dev gtk+3.0-dev libevdev-dev meson mtdev-dev $_depends_tools"
checkdepends="diffutils bash"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-libs
	$pkgname-debug-gui:_debug_gui
	$pkgname-tools
	$pkgname-zsh-completion
	"
install="$pkgname.post-upgrade"
source="https://gitlab.freedesktop.org/libinput/libinput/-/archive/$pkgver/libinput-$pkgver.tar.gz"

# secfixes:
#   1.20.1-r0:
#     - CVE-2022-1215

build() {
	abuild-meson \
		-Ddocumentation=false \
		-Dlibwacom=false \
		-Ddebug-gui=true \
		-Dtests=false builddir/
	meson compile ${JOBS:+-j ${JOBS}} -C builddir/
}

check() {
	meson test --no-rebuild -v -C builddir
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C builddir
}

libs() {
	default_libs

	mv "$pkgdir"/usr/lib/udev "$subpkgdir"/usr/lib
	mkdir -p "$subpkgdir"/usr/share/
	mv "$pkgdir"/usr/share/libinput "$subpkgdir"/usr/share
}

tools() {
	pkgdesc="CLI helper tools for debugging libinput"
	depends="$pkgname=$pkgver-r$pkgrel $_depends_tools"

	# Q: Maybe move all tools (even libinput-list-devices, libinput-quirks)
	#    into -tools? (jirutka)
	amove usr/libexec/libinput/libinput-analyze*
	amove usr/libexec/libinput/libinput-debug*
	amove usr/libexec/libinput/libinput-measure*
	amove usr/libexec/libinput/libinput-record
	amove usr/libexec/libinput/libinput-replay
}

_debug_gui() {
	pkgdesc="GTK-based visual debug helper for libinput"
	depends=""

	amove usr/libexec/libinput/libinput-debug-gui
}

sha512sums="
510273d68f2d4cfa61564a706b1f334f6bfca0d1c8faf0bb8aa656cf3fbd5e38d79d6fbaa01a20d38bc15777c9afc341e4ed08d35ef367ef3803ce788cbc4a0e  libinput-1.21.0.tar.gz
"
